/*
 * Copyright (C) 2008 Alessandro Sivieri <alessandro.sivieri@chimera-bellerofonte.eu>.
 *
 *  This file is part of Daex.
 *
 *  Daex is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Foobar is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */
package eu.chimera_bellerofonte.tesi.ui.models;

import java.util.Collections;
import java.util.Comparator;
import java.util.Vector;

import javax.swing.DefaultComboBoxModel;

import eu.chimera_bellerofonte.tesi.datatypes.Genre;


/**
 * Classe di utilizzo del modello del ComboBox dei generi nella
 * GUI; viene creato per comodita' di uso dal manager del programma,
 * non aggiunge (al momento) nulla di nuovo al modello standard.
 * 
 * @author Sivieri Alessandro
 * @author Vitucci Nicola
 * @version 17/mag/07
 */
public class DaexComboBoxModel extends DefaultComboBoxModel
{

	static final long serialVersionUID = 1L;

	/**
	 * Costruttore; setta gli attributi di classe con i
	 * valori specificati.
	 * 
	 */
	public DaexComboBoxModel()
	{
		Vector<Genre> elements=new Vector<Genre>(0);
		for(Genre g: Genre.values())
			elements.add(g);
		Collections.sort(elements, new Comparator<Genre>()
		{

			public int compare(Genre o1, Genre o2)
			{
				return o1.toString().compareTo(o2.toString());
			}
			
		});
		for(Genre g: elements)
			this.addElement(g.getName());
	}

	/**
	 * @see javax.swing.DefaultComboBoxModel#getSelectedItem()
	 */
	@Override
	public Object getSelectedItem()
	{
		Object o=super.getSelectedItem();
		if(o instanceof Genre)
		{
			o=((Genre) o).getName();
		}
		return o;
	}

}
